<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="applicable-device" content="pc">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="icon" href="/icon.png" />
    <link rel="stylesheet" href="/static/index/css/reset.css">
    <link rel="stylesheet" href="/static/index/lib/bootstrap.css">
    <link rel="stylesheet" href="/static/index/css/common.css">
    <link rel="stylesheet" href="/static/index/css/home.css">
    <link rel="stylesheet" href="/static/index/css/users.css">
    <script src="/static/index/lib/jquery-2.1.4.js"></script>
    <script src="/static/index/lib/bootstrap.min.js"></script>
    <script type="text/javascript" src="/static/index/lib/template.js"></script>
    <script>
            var _hmt = _hmt || [];
            (function() {
              var hm = document.createElement("script");
              hm.src = "https://hm.baidu.com/hm.js?8b340ebdd740974de9d621b14ab09b43";
              var s = document.getElementsByTagName("script")[0]; 
              s.parentNode.insertBefore(hm, s);
            })();
        </script>
</head>

<body>
    {include file="public/push"}
    {include file="public/usersHeader"}
    <div class="widthFullScreen">
        <div class="wdSafe user_body clearfix">
            {include file="public/usersLeftNav"}
            <!-- left over -->
            <div class="pull-right right_wrap">
                <div class="nav_common border-top">
                    <ol class="breadcrumb pull-left">
                        <li><a href="/users/index">用户中心</a></li>
                        <li><a href="/users/index">我的资料</a></li>
                        <li><a href="/users/companyCase">资质案例</a></li>
                        <li class="active">编辑案例</li>
                    </ol>
                    
                </div>
                <div class="comUser_wrap" id="formHtml">
                    <div class="form-horizontal">
                        <form method="post" id="zhizhiaoForm" enctype="multipart/form-data">
                            <div class="form-group">
                                <label for="" class="col-sm-2 control-label">
                                    <span class="colorRed">*</span>&nbsp;&nbsp;案例图片
                                </label>
                                <div class="col-sm-7">
                                    <div class="imgWrap_upload">
                                        <div class="upLoadImg_style">
                                            <img id="logoPic" src="https://img.qikuai100.com/bg.png" />
                                            <input type="file" name="file" id="logoIpt" accept="image/*" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                        <div class="form-group">
                            <label for="two" class="col-sm-2 control-label">
                                <span class="colorRed">*</span>&nbsp;&nbsp;合作公司介绍
                            </label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control ipt_styleSub" name="" placeholder="请输入合作公司名称" id="company_name" value="" />
                                <span class="help-block">系统会自动屏蔽部分企业名称进行展示</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="one" class="col-sm-2 control-label">
                                合作业务介绍
                            </label>
                            <div class="col-sm-10">
                                <textarea class="form-control textarea_style" placeholder="请详细介绍合作业务" name="" rows="" cols="" id="service_desc"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="two" class="col-sm-2 control-label">
                                <span class="colorRed">*</span>&nbsp;&nbsp;资质类别
                            </label>
                            <div class="col-sm-10">
                                <select name="" class="selectStyle pull-left" style="margin-right: 20px;" id="provenceSelect">
                                    <option value="">选择资质类型</option>
                                </select>
                                <select name="" class="selectStyle pull-left" id="citySelect">
                                    <option value="">选择资质专业</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="two" class="col-sm-2 control-label">
                                <span class="colorRed">*</span>&nbsp;&nbsp;办理周期
                            </label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control ipt_styleSub" name="" placeholder="请输入办理周期，例如一周" id="project_cycle" value="" />
                            </div>
                        </div>
                        <!-- <div class="form-group">
                            <label for="two" class="col-sm-2 control-label">
                                <span class="colorRed">*</span>&nbsp;&nbsp;办理周期
                            </label>
                            <div class="col-sm-10">
                                <select name="" class="selectStyle pull-left" id="project_cycle">
                                    <option value="">选择办理周期</option>
                                </select>
                            </div>
                        </div> -->
                        <div class="form-group">
                            <label for="two" class="col-sm-2 control-label">
                                <span class="colorRed">*</span>&nbsp;&nbsp;办理费用
                            </label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control ipt_styleSub" name="" placeholder="请输入办理费用，例如1.5万" id="project_price" value="" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="one" class="col-sm-2 control-label">
                                人员配置
                            </label>
                            <div class="col-sm-10">
                                <textarea class="form-control textarea_style" placeholder="请详细填写人员配置情况" name="" rows="" cols="" id="staff"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="two" class="col-sm-2 control-label">
                                <span class="colorRed">*</span>&nbsp;&nbsp;是否显示
                            </label>
                            <div class="col-sm-10" id="chooseHidden">
                                <label class="radio-inline">
                                   <input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="1">显示
                                </label>
                                <label class="radio-inline">
                                  <input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="0">隐藏
                                </label>
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <div class="submitBtn" onclick="submitDate()">保存</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- right over -->
        </div>
    </div>
    <div class="widthFullScreen heightGray"></div>
    {include file="public/footer"}

    <script type="text/javascript" src="/static/index/layer/layer.js"></script>
    <script type="text/javascript">
        var baseUrl = 'https://api.qikuai100.com/',
            uid = localStorage.getItem("uid"),
            id = {$id};

        var str = ''; // 初始化资质
        var strArr = [];

        $(function() {
            /**
            * 上传照片
            */
            var uploadingLogo = false;
            $("#logoIpt").on("change", function() {
                if (uploadingLogo) {
                    layer.msg("文件正在上传中，请稍候");
                    return false;
                }
                var indexLogo = layer.load(1, {shade: false});
                $.ajax({
                    url: baseUrl + "api/img/upload",
                    type: 'POST',
                    cache: false,
                    data: new FormData($('#zhizhiaoForm')[0]),
                    processData: false,
                    contentType: false,
                    dataType: "json",
                    beforeSend: function() {
                        uploadingLogo = true;
                    },
                    success: function(data) {
                        layer.close(indexLogo);
                        if (data.ret == 0) {
                            $("#logoPic").attr("src", data.data.url);
                        } else {
                            layer.msg("上传图片失败");
                        }
                        uploadingLogo = false;
                    }
                });
            });
            
            initDate();
           
        });
       

        var catgeroyList = [];
        // 加载资质分类数据
        function initCatgroyList() {
            $.ajax({
                type: "POST",
                url: baseUrl + "api/category/list",
                data: {
                    "type": 1
                },
                success: function(result) {
                    if(result.ret == 0) {
                        catgeroyList = result.data;
                        addressInit();
                    }
                }
            });
        };

        /**
        * 初始化资质
        */
        function addressInit(){
            var strOne = '';
            var nameOne = strArr[0];
            for(var i = 0; i < catgeroyList.length; i++){
                if(catgeroyList[i].category_name == nameOne){
                    strOne += '<option selected = "selected" value="'+ catgeroyList[i].category_name +'" dId="'+ catgeroyList[i].id +'">'+ catgeroyList[i].category_name +'</option>'; 
                }else{
                    strOne += '<option value="'+ catgeroyList[i].category_name +'" dId="'+ catgeroyList[i].id +'">'+ catgeroyList[i].category_name +'</option>'; 
                }
                
            }
            $('#provenceSelect').html(strOne);
            initCity();
        }

        function initCity(){
            var sss = $('#provenceSelect').children('option:selected').attr("dId");
            var jsonCity = [],
                strHtml = '';
            var nameOne = strArr[1];
            for(var i = 0; i < catgeroyList.length; i++){
                if(sss == catgeroyList[i].id){
                    jsonCity = catgeroyList[i].subcategoy;
                }
            }
            for(var i = 0; i < jsonCity.length; i++){
                if(jsonCity[i].category_name == nameOne){
                    strHtml += '<option selected = "selected" value="'+ jsonCity[i].category_name +'" dId="'+ jsonCity[i].id +'">'+ jsonCity[i].category_name +'</option>';
                }else{
                    strHtml += '<option value="'+ jsonCity[i].category_name +'" dId="'+ jsonCity[i].id +'">'+ jsonCity[i].category_name +'</option>';
                } 
            }
            $('#citySelect').html(strHtml);
        }


        $('#formHtml').on("change", "#provenceSelect", function() {
            var sss = $(this).children('option:selected').attr("dId");
            var jsonCity = [],
                strHtml = '';
            for(var i = 0; i < catgeroyList.length; i++){
                if(sss == catgeroyList[i].id){
                    jsonCity = catgeroyList[i].subcategoy;
                }
            }
            for(var i = 0; i < jsonCity.length; i++){
                strHtml += '<option value="'+ jsonCity[i].category_name +'" dId="'+ jsonCity[i].id +'">'+ jsonCity[i].category_name +'</option>'; 
            }
            $('#citySelect').html(strHtml);
        });


        /**
        * 初始化数据
        */
        function initDate(){
            $.ajax({
                type: "POST",
                url: baseUrl + "api/case/getOne",
                data: {
                    "uid": uid,
                    "id": id
                },
                success: function(result) {
                    if(result.ret == 0) {
                        $('#company_name').val(result.data.company_name),
                        $("#service_desc").val(result.data.service_desc),
                        $('#logoPic').attr("src",result.data.poster),
                        $('#project_cycle').val(result.data.project_cycle),
                        $('#project_price').val(result.data.project_price),
                        $('#staff').val(result.data.staff);
                        if(result.data.is_hidden == 0){
                            $('#inlineRadio2').attr("checked","checked");
                            $('#inlineRadio1').removeAttr("checked");
                        }else{
                            $('#inlineRadio2').removeAttr("checked");
                            $('#inlineRadio1').attr("checked","checked");
                        }
                        $('#provenceSelect').val(result.data.project_price);
                        str = result.data.category_name;
                        strArr = str.split("-");
                         initCatgroyList();
                    }
                }
            });
        }

        
        /**
         * 提交数据
         */
        function submitDate() {
            var is_hidden = 1;
            $('#chooseHidden').find("input").each(function(i,item){
                if($(this).prop("checked")){
                    is_hidden = $(this).val();
                }
            });
            var company_name = $('#company_name').val(),
                service_desc = $("#service_desc").val(),
                avatar = $('#logoPic').attr("src"),
                category_id = $('#citySelect').children('option:selected').attr("dId"),
                project_cycle = $('#project_cycle').val(),
                project_price = $('#project_price').val(),
                staff = $('#staff').val();
            if($.trim(avatar) == '' || $.trim(avatar) == 'https://img.qikuai100.com/bg.png'){
                layer.msg("请上传案例图片");
                return;
            }
            if($.trim(company_name) == ''){
                layer.msg("请输入合作公司名称");
                return;
            }
            // if($.trim(service_desc) == ''){
            //     layer.msg("请输入合作业务介绍");
            //     return;
            // }
            if($.trim(category_id) == ''){
                layer.msg("请选择资质专业");
                return;
            }
            if($.trim(project_cycle) == ''){
                layer.msg("请输入办理周期");
                return;
            }
            if($.trim(project_price) == ''){
                layer.msg("请输入办理费用");
                return;
            }
            // if($.trim(staff) == ''){
            //     layer.msg("请输入人员配置");
            //     return;
            // }
            $.ajax({
                type: "POST",
                url: baseUrl + "api/case/add",
                data: {
                    id: id,
                    uid: uid,
                    poster: avatar,
                    company_name: company_name,
                    service_desc: service_desc,
                    category_id: category_id,
                    project_cycle: project_cycle,
                    project_price: project_price,
                    staff: staff,
                    is_hidden: is_hidden
                },
                success: function(result) {
                    if (result.ret == 0) {    
                        layer.msg("编辑成功");             
                        setTimeout(function(){
                            window.location.href = '/users/companyCase';
                        }, 1000);
                    } else {
                        layer.msg(result.res_info);
                    }
                }
            });
        };
    </script>
</body>

</html>